class source_view =
    object(this)

val _lang_mime_type = "text/x-ocaml"
val _lang_name = "ocaml"
val _use_mime_type = true
val mutable _language_manager = GSourceView2.source_language_manager ~default:true
val mutable _endInit = false
val mutable _lang = Obj.magic None

method private initLang = 
    _lang <-  begin
  if _use_mime_type then
    (match _language_manager#guess_language ~content_type:_lang_mime_type () with
        Some x -> x
      | None -> failwith (Printf.sprintf "no language for %s" _lang_mime_type))
  else
    (match _language_manager#language _lang_name with
        Some x -> x
      | None -> failwith (Printf.sprintf "can't load %s" _lang_name))
    end

method advanceMode txt =  
  txt#source_buffer#set_highlight_matching_brackets true;
  this#initLang;
  txt#source_buffer#set_language (Some _lang);
  txt#source_buffer#set_highlight_syntax true;
  txt#set_smart_home_end `AFTER;
  txt#set_draw_spaces [];
  ignore(txt#draw_spaces);
  txt#source_buffer#begin_not_undoable_action ();
  txt#source_buffer#end_not_undoable_action ()
  
method newTextView ~edit ~advance (pack: GBin.scrolled_window) =
  let source_view = GSourceView2.source_view
    ~auto_indent:true
    ~editable:edit
    ~insert_spaces_instead_of_tabs:true ~tab_width:2
    ~show_line_numbers:edit
    ~show_right_margin:true
    ~packing:pack#add () in 
  (if(edit && advance || edit && not(_endInit)) 
  then (Popup.add source_view; Function._listText := !Function._listText@[source_view]));
  (if(advance && _endInit) then this#advanceMode source_view);
  source_view#misc#modify_base [`NORMAL, `RGB (Settings.getBgColor ())]; 
  source_view#misc#modify_font_by_name (Settings.getFont ());
  source_view#misc#modify_text [`NORMAL, `RGB (Settings.getFgColor ())];
  source_view

method endInit = _endInit <- true
method getEndInit = _endInit
    end
